package cn.edu.nuc.fourth.services.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.edu.nuc.fourth.dao.AnnounceMapper;
import cn.edu.nuc.fourth.dto.PageInfo;
import cn.edu.nuc.fourth.model.Announce;
import cn.edu.nuc.fourth.services.interfaces.AdminService;

@Service
public class AdminServiceImpl implements AdminService {

	@Autowired
	private AnnounceMapper mapper;

	@Override
	public PageInfo announceList(Integer current) {

		if (current <= 0) {
			current = 1;
		}
		Integer count = mapper.count();
		PageInfo pageInfo = new PageInfo(current);
		List<Announce> list = mapper.page(pageInfo.getStart(), pageInfo.getOffset());
		pageInfo.setList(list);
		pageInfo.setCount(count);

		return pageInfo;
	}

	/**
	 * 添加公告
	 */
	@Override
	public Integer announceadd(Announce announce) {

		announce.setDepartment("市教育局");
		announce.setAstate(0);
		Integer result = mapper.insert(announce);
		return result;
	}

	/**
	 * 初始化一条公告记录
	 */
	@Override
	public Announce oneAnno(Integer aid) {

		Announce a = mapper.selectByPrimaryKey(aid);
		return a;
	}

	/**
	 * 执行修改
	 */
	@Override
	public Integer announceedit(Announce announce) {

		Integer result = mapper.updateByPrimaryKey(announce);

		return result;
	}

	@Override
	public Integer stateeidt(Announce announce) {

		Integer result = mapper.updateByPrimaryKeySelective(announce);
		return result;
	}

	@Override
	public List<Announce> ajaxlist(Integer astate) {

		List<Announce> list = mapper.findBystate(astate);
		return list;
	}

}
